package com.qk.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.dto.ActivityDto;
import com.qk.entity.Activity;
import com.qk.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/activities")
public class ActivityController {
    @Autowired
    private ActivityService activityService;
/**
 * 列表活动查询
 */
@GetMapping
    public Result query(ActivityDto activityDto) {
        log.info("查询列表{}", activityDto);
        PageResult<Activity> pageResult = activityService.query(activityDto);
        return Result.success(pageResult);

    }
    /**
     * 删除活动
     */
@DeleteMapping ("/{id}")
    public Result delete(@PathVariable Integer id) {
        log.info("删除活动{}", id);
        activityService.delete(id);
        return Result.success();
    }
    /**
     * 添加活动
     */
    @PostMapping
    public Result add(@RequestBody Activity activity) {
        log.info("添加活动{}", activity);
        activityService.add(activity);
        return Result.success();
    }
    /**
     * 根据ID查询活动
     */
    @GetMapping("/{id}")
    public Result selectById(@PathVariable Integer id) {
        log.info("查询活动{}", id);
        Activity activity = activityService.selectById(id);
        return Result.success(activity);
    }
    @PutMapping
    public Result update(@RequestBody Activity activity) {
        log.info("修改活动{}", activity);
        activityService.update(activity);
        return Result.success();
    }
    /**
     * 根据活动类型查询 活动
     */
    @GetMapping("/type/{type}")
    public Result queryByType(@PathVariable Integer type) {
        log.info("查询活动{}", type);
        List<Activity> list = activityService.queryByType(type);
        return Result.success(list);
    }

}
